﻿namespace lucere.io.concurrency
{

	///<summary>
	/// Use this <see cref="LockFactory"/> to disable locking entirely.
	/// Only one instance of this lock is created.  You should call <see cref="GetNoLockFactory"/>
	/// to get the instance.
	/// <see cref="LockFactory"/> 
	///</summary>
	public class NoLockFactory : LockFactory
	{
		// Single instance returned whenever makeLock is called.
		private static NoLock singletonLock = new NoLock();
		private static NoLockFactory singleton = new NoLockFactory();

		public static NoLockFactory GetNoLockFactory()
		{
			return singleton;
		}

		///<summary>
		///Return a new Lock instance identified by lockName.
		///<param name="lockName">name of the lock to be created.</param>
		///</summary>
		public override ILock MakeLock(string lockName)
		{
			return singletonLock;
		}

		///<summary>
		/// Attempt to clear (forcefully unlock and remove) the
		/// specified lock.  Only call this at a time when you are
		/// certain this lock is no longer in use.
		/// <param name="lockName">name of the lock to be cleared.</param>
		/// </summary>
		public override void ClearLock(string lockName) { }
	}
}